package com.wwwarehouse.carddesk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.common.bean.carddesk.CardDeskMessageStableCardBean;

import java.util.List;

public class MessageDetailsAdapter extends BaseAdapter {
    private Context mContext;
    private List<CardDeskMessageStableCardBean.TasksBean> mCardDeskFunctionList;
    private int mItemHeight;

    /**
     * 物：ITEM
     资源：RESOURCE
     */
//    private static String RELATED_TYPE_ITEM = "ITEM";
//    private static String RELATED_TYPE_RESOURCE = "RESOURCE";

    public MessageDetailsAdapter(Context context, List<CardDeskMessageStableCardBean.TasksBean> cardDeskFunctionList, int itemHeight) {
        this.mContext = context;
        this.mCardDeskFunctionList = cardDeskFunctionList;
        this.mItemHeight = itemHeight;
    }

    public void setmItemHeight(int itemHeight){
        this.mItemHeight = itemHeight;
    }

    @Override
    public int getCount() {
        return mCardDeskFunctionList == null ? 0 : mCardDeskFunctionList.size();
    }

    @Override
    public Object getItem(int position) {
        return mCardDeskFunctionList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CardDeskMessageStableCardBean.TasksBean infoCardsBean = mCardDeskFunctionList.get(position);
        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_message_details, null);
            holder = new ViewHolder();
            holder.iconImg = (ImageView) convertView.findViewById(R.id.iv_icon);
            holder.nameTxt = (TextView) convertView.findViewById(R.id.tv_name);

            convertView.setTag(holder);

            AbsListView.LayoutParams params =  new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            params.height = mItemHeight;
            convertView.setLayoutParams(params);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        BaseApplication.getApplicationInstance().displayImg(infoCardsBean.getTaskImgUrl(),holder.iconImg);
        holder.nameTxt.setText(infoCardsBean.getTaskName());

        return convertView;
    }

    private class ViewHolder {
        private ImageView iconImg;
        private TextView nameTxt;
    }
}